package com.finalministry.db.objects;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;

import com.finalministry.db.objects.enums.FlagsTagsNotesEnum;

/**
 * Base class for Objects which are enabled for FlagTagNoteAble
 * 
 * @author admin
 * 
 */
// @Entity
public class FlagTagNoteAbleBase extends AbstractDO implements IFlagTagNoteAble {

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "FlagTagNoteAbleBase")
	private List<FlagsTagsNotes> flags = new ArrayList<FlagsTagsNotes>();
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "FlagTagNoteAbleBase")
	private List<FlagsTagsNotes> tags = new ArrayList<FlagsTagsNotes>();
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "FlagTagNoteAbleBase")
	private List<FlagsTagsNotes> notes = new ArrayList<FlagsTagsNotes>();

	public String getObjectName() {
		return this.getClass().getSimpleName();
	}

	/**
	 * Method to set the flags, tags and notes from the DAO
	 * 
	 * @param ftnList
	 */
	public void setFlagsTagsNotes(List<FlagsTagsNotes> ftnList) {

		flags.clear();
		tags.clear();
		notes.clear();

		for (FlagsTagsNotes flagsTagsNotes : ftnList) {

			if (flagsTagsNotes.getType().equals(FlagsTagsNotesEnum.FLAG)) {
				flags.add(flagsTagsNotes);
			}

			if (flagsTagsNotes.getType().equals(FlagsTagsNotesEnum.TAG)) {
				tags.add(flagsTagsNotes);
			}

			if (flagsTagsNotes.getType().equals(FlagsTagsNotesEnum.NOTE)) {
				notes.add(flagsTagsNotes);
			}
		}
	}

	public List<FlagsTagsNotes> getFlags() {
		return flags;
	}

	public List<FlagsTagsNotes> getTags() {
		return tags;
	}

	public List<FlagsTagsNotes> getNotes() {
		return notes;
	}

}
